﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;

public partial class codelist : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    //删除

    protected void gv_department_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {

        string sqlstr = "delete from t_department where idepartment_ID='" + gv_department.DataKeys[e.RowIndex].Value.ToString() + "'";

        string str = ConfigurationManager.ConnectionStrings["DevMgmntConnectionString"].ConnectionString.ToString();
        SqlConnection cn33 = new SqlConnection(str);
        cn33.Open();
        SqlCommand sqlcom = new SqlCommand(sqlstr, cn33);

        sqlcom.ExecuteNonQuery();

        cn33.Close();

        gv_department.DataBind();

    }


    protected void bt_departmentAdd_Click(object sender, EventArgs e)
    {
        TextBox t1 = tx_departmentID;
        TextBox t2 = tx_departmentName;
        try
        {
            string str = ConfigurationManager.ConnectionStrings["DevMgmntConnectionString"].ConnectionString.ToString();
            SqlConnection cn33 = new SqlConnection(str);
            cn33.Open();
            str = "insert INTO t_department (idepartment_ID,sdepartmentName) values ('" + t1.Text.Trim() + "','" + t2.Text.Trim() + "')";
            Console.WriteLine("btn_departmentAdd:{0}", str);
            SqlCommand cmd2 = new SqlCommand(str, cn33);
            cmd2.ExecuteNonQuery();
            cn33.Close();
        }
        catch (Exception ex)
        {
            Console.WriteLine("传递过来的异常值为：{0}", ex);
        }

        gv_department.DataBind();
    }
}